package com.agger.eurekaclientmanagerservice.controller;

import com.agger.eurekacommonapi.service.BaseManagerController;
import com.agger.eurekacommonapi.service.BaseUserController;
import com.agger.eurekacommonapi.vo.ResultData;
import com.agger.eurekacommonapi.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @classname: managerController
 * @description:
 * @author chenhx
 * @date 2020-04-22 12:05:52
 */
@Slf4j
@RestController
@RequestMapping("/man")
public class ManagerController implements BaseManagerController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private BaseUserController userService;

    /**
     * @Title: helloManager
     * @Description: 使用RestTemplate，通过Eureka访问user服务的接口
     * @param
     * @return java.lang.String
     * @author chenhx
     * @date 2020-04-23 11:05:14
     */
    @Override
    public String helloManager(String name) {
        return restTemplate.getForObject("http://eureka-client-user-service/user/hello/{name}", String.class,name);
    }

    /**
     * @Title: helloManager2
     * @Description: 通过Feign接口调用user服务
     * @param
     * @return java.lang.String
     * @author chenhx
     * @date 2020-04-23 11:05:07
     */
    @Override
    public String helloManager2(String name) {
        log.info("这是{}，值：{}","manager",name);
//        log.warn("这是{}，值：{}","manager",name);
//        log.error("这是{}，值：{}","manager",name);
//        log.debug("这是{}，值：{}","manager",name);
        return userService.sayHello(name);
    }

    /**
     * @Title: addUser
     * @Description: 通过Feign接口调用user服务
     * @param 
     * @return com.agger.eurekacommonapi.vo.ResultData
     * @author chenhx
     * @date 2020-04-23 11:04:59
     */
    @Override
    public ResultData addUser(UserVO user) {
        return userService.addUser(user);
    }

    @Override
    public String headMan(String man, String foo) {
        return String.format("请求头 X-Request-Foo=%s, man=%s",foo,man) ;
    }
}
